<?php
class RatingsController extends AppController {

	var $name = 'Ratings';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Rating->recursive = 0;
		$this->set('ratings', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Rating', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('rating', $this->Rating->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Rating->create();
			if ($this->Rating->save($this->data)) {
				$this->Session->setFlash(__('The Rating has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Rating could not be saved. Please, try again.', true));
			}
		}
		$facultets = $this->Rating->Facultet->find('list');
		$professions = $this->Rating->Profession->find('list');
		$learningforms = $this->Rating->Learningform->find('list');
		$learningtypes = $this->Rating->Learningtype->find('list');
		$this->set(compact('facultets', 'professions', 'learningforms', 'learningtypes'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Rating', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Rating->save($this->data)) {
				$this->Session->setFlash(__('The Rating has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Rating could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Rating->read(null, $id);
		}
		$facultets = $this->Rating->Facultet->find('list');
		$professions = $this->Rating->Profession->find('list');
		$learningforms = $this->Rating->Learningform->find('list');
		$learningtypes = $this->Rating->Learningtype->find('list');
		$this->set(compact('facultets','professions','learningforms','learningtypes'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Rating', true));
			$this->redirect(array('action' => 'index'));
		}
		if ($this->Rating->del($id)) {
			$this->Session->setFlash(__('Rating deleted', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('The Rating could not be deleted. Please, try again.', true));
		$this->redirect(array('action' => 'index'));
	}

}
?>